# -*- coding: utf-8 -*-

from method import *
import threading,time
from concurrent.futures import ThreadPoolExecutor
# write_yaml(r"D:\python\pythonProject\test\add_employee_requests.yaml",data1)
# write_yaml(r"D:\python\pythonProject\test\add_employee_requests.yaml",data_uat1)

# write_yaml(r"D:\python\pythonProject\test\requests.yaml",oa_data_154)

def login():
    #登录接口
    url = get_url('login')
    headers = get_headers('login')
    data = get_data('login')
    ree = send_requests('login', url, data, headers)
    a1 = json.loads(ree.text)
    token = a1['data']['token']
    return token


def pendingPage():
    start_time = time.time()  # 记录开始时间
    # 调用列表接口，获取列表中三个字段的数据
    url = get_url('auditList')
    headers = get_headers('auditList')
    headers['Authorization']=login()
    data = get_data('auditList')
    ree = send_requests('auditList', url, data, headers)
    a = json.loads(ree.text)
    list_all = a['data']['records']
    #流程名称列表
    list1 = []
    #流程发起人列表
    list2 = []
    #机构简称列表
    list3 = []
    for i in list_all:
        list1.append(i['auditConfigName'])
        list2.append(i['applyName'])
        if i['clientName'] is not None:
            list3.append(i['clientName'])

    # 处理机构简称列表数据
    original_list = list(set(list3))
    unique_list=deal_list(original_list)
    #调用下拉框接口，获取下拉框选项数据
    url1 = get_url('auditDropDown')
    headers1 = get_headers('auditDropDown')
    headers1['Authorization'] = login()
    data1 = get_data('auditDropDown')
    ree1 = send_requests('auditDropDown', url1, data1, headers1)
    a1 = json.loads(ree1.text)
    # 流程名称下拉框列表
    list_auditConfigName = []
    # 流程发起人下拉框列表
    list_applyName = []
    # 机构简称下拉框列表
    list_examineContractName=[]

    for i in a1['data']['applyName']:
        list_applyName.append(i['label'])
    for i in a1['data']['auditConfigName']:
        list_auditConfigName.append(i['label'])
    for i in a1['data']['examineContractName']:
        list_examineContractName.append(i['label'])

    #判断流程名称结果是否一致
    unique(list1,list_auditConfigName)

    # 判断流程发起人结果是否一致
    unique(list2, list_applyName)

    # 判断机构简称结果是否一致
    unique(unique_list,list_examineContractName)

    print("待处理页面流程名称有" + str(len(set(list1))) + '个 ：' + str(set(list1)))
    print("待处理页面流程发起人有" + str(len(set(list2))) + '个 ：' + str(set(list2)))
    print("待处理页面机构简称有" + str(len(unique_list)) + '个 ：' + str(unique_list))
    end_time = time.time()  # 记录结束时间
    run_time = end_time - start_time  # 计算运行时间（单位为秒）
    print("脚本运行时间：", round(run_time, 2), '秒')
    print("--------------------------------------end-------------------------------")

def processedpage():
    start_time = time.time()  # 记录开始时间
    # 调用列表接口，获取列表中三个字段的数据
    url = get_url('auditpageList')
    headers = get_headers('auditpageList')
    headers['Authorization'] = login()
    data = get_data('auditpageList')
    ree = send_requests('auditpageList', url, data, headers)
    a = json.loads(ree.text)
    list_all = a['data']['records']
    #流程名称列表
    list1 = []
    #流程发起人列表
    list2 = []
    #机构简称列表
    list3 = []
    for i in list_all:
        list1.append(i['auditConfigName'])
        list2.append(i['applyName'])
        if i['clientName'] is not None:
            list3.append(i['clientName'])

    # 处理机构简称列表数据
    original_list = list(set(list3))
    unique_list = deal_list(original_list)
    # 调用下拉框接口，获取下拉框选项数据
    url1 = get_url('auditgetDropDown')
    headers1 = get_headers('auditgetDropDown')
    headers1['Authorization'] = login()
    data1 = get_data('auditgetDropDown')
    ree1 = send_requests('auditgetDropDown', url1, data1, headers1)
    a1 = json.loads(ree1.text)

    # 流程名称下拉框列表
    list_auditConfigName = []
    # 流程发起人下拉框列表
    list_applyName = []
    # 机构简称下拉框列表
    list_examineContractName=[]

    for i in a1['data']['applyName']:
        list_applyName.append(i['label'])
    for i in a1['data']['auditConfigName']:
        list_auditConfigName.append(i['label'])
    for i in a1['data']['examineContractName']:
        list_examineContractName.append(i['label'])

    # 判断流程名称结果是否一致
    unique(list1, list_auditConfigName)

    # 判断流程发起人结果是否一致
    unique(list2, list_applyName)

    # 判断机构简称结果是否一致
    unique(unique_list, list_examineContractName)

    print("已处理页面流程名称有" + str(len(set(list1))) + '个 ：' + str(set(list1)))
    print("已处理页面流程发起人有" + str(len(set(list2))) + '个 ：' + str(set(list2)))
    print("已处理页面机构简称有" + str(len(unique_list)) + '个 ：' + str(unique_list))
    end_time = time.time()  # 记录结束时间
    run_time = end_time - start_time  # 计算运行时间（单位为秒）
    print("脚本运行时间：", round(run_time, 2), '秒')
    print("--------------------------------------end-------------------------------")


def ccmypage():
    start_time = time.time()  # 记录开始时间
    # 调用列表接口，获取列表中三个字段的数据
    url = get_url('auditpageList2')
    headers = get_headers('auditpageList2')
    headers['Authorization'] = login()
    data = get_data('auditpageList2')
    ree = send_requests('auditpageList2', url, data, headers)
    a = json.loads(ree.text)
    list_all = a['data']['records']
    #流程名称列表
    list1 = []
    #流程发起人列表
    list2 = []
    #机构简称列表
    list3 = []
    for i in list_all:
        list1.append(i['auditConfigName'])
        list2.append(i['applyName'])
        if i['clientName'] is not None:
            list3.append(i['clientName'])

    # 处理机构简称列表数据
    original_list = list(set(list3))
    unique_list = deal_list(original_list)
    # 调用下拉框接口，获取下拉框选项数据
    url1 = get_url('auditgetDropDown2')
    headers1 = get_headers('auditgetDropDown2')
    headers1['Authorization'] = login()
    data1 = get_data('auditgetDropDown2')
    ree1 = send_requests('auditgetDropDown2', url1, data1, headers1)
    a1 = json.loads(ree1.text)

    # 流程名称下拉框列表
    list_auditConfigName = []
    # 流程发起人下拉框列表
    list_applyName = []
    # 机构简称下拉框列表
    list_examineContractName=[]

    for i in a1['data']['applyName']:
        list_applyName.append(i['label'])
    for i in a1['data']['auditConfigName']:
        list_auditConfigName.append(i['label'])
    for i in a1['data']['examineContractName']:
        list_examineContractName.append(i['label'])

    # 判断流程名称结果是否一致
    unique(list1, list_auditConfigName)

    # 判断流程发起人结果是否一致
    unique(list2, list_applyName)

    # 判断机构简称结果是否一致
    unique(unique_list, list_examineContractName)

    print("抄送我页面流程名称有" + str(len(set(list1))) + '个 ：' + str(set(list1)))
    print("抄送我页面流程发起人有" + str(len(set(list2))) + '个 ：' + str(set(list2)))
    print("抄送我页面机构简称有" + str(len(unique_list)) + '个 ：' + str(unique_list))
    end_time = time.time()  # 记录结束时间
    run_time = end_time - start_time  # 计算运行时间（单位为秒）
    print("脚本运行时间：", round(run_time, 2), '秒')
    print("--------------------------------------end-------------------------------")


def pageinitiated():
    start_time = time.time()  # 记录开始时间
    # 调用列表接口，获取列表中三个字段的数据
    url = get_url('auditpageList3')
    headers = get_headers('auditpageList3')
    headers['Authorization'] = login()
    data = get_data('auditpageList3')
    ree = send_requests('auditpageList3', url, data, headers)
    a = json.loads(ree.text)
    list_all = a['data']['records']
    #流程名称列表
    list1 = []
    #流程发起人列表
    list2 = []
    #机构简称列表
    list3 = []
    for i in list_all:
        list1.append(i['auditConfigName'])
        list2.append(i['applyName'])
        if i['clientName'] is not None:
            list3.append(i['clientName'])

    # 处理机构简称列表数据
    original_list = list(set(list3))
    unique_list = deal_list(original_list)
    # 调用下拉框接口，获取下拉框选项数据
    url1 = get_url('auditgetDropDown3')
    headers1 = get_headers('auditgetDropDown3')
    headers1['Authorization'] = login()
    data1 =get_data('auditgetDropDown3')
    ree1 = send_requests('auditgetDropDown3', url1, data1, headers1)
    a1 = json.loads(ree1.text)

    # 流程名称下拉框列表
    list_auditConfigName = []
    # 流程发起人下拉框列表
    list_applyName = []
    # 机构简称下拉框列表
    list_examineContractName=[]

    for i in a1['data']['applyName']:
        list_applyName.append(i['label'])
    for i in a1['data']['auditConfigName']:
        list_auditConfigName.append(i['label'])
    for i in a1['data']['examineContractName']:
        list_examineContractName.append(i['label'])

    # 判断流程名称结果是否一致
    unique(list1, list_auditConfigName)

    # 判断流程发起人结果是否一致
    unique(list2, list_applyName)

    # 判断机构简称结果是否一致
    unique(unique_list, list_examineContractName)

    print("已发起页面流程名称有" + str(len(set(list1))) + '个 ：' + str(set(list1)))
    print("已发起页面流程发起人有" + str(len(set(list2))) + '个 ：' + str(set(list2)))
    print("已发起页面机构简称有" + str(len(unique_list)) + '个 ：' + str(unique_list))
    end_time = time.time()  # 记录结束时间
    run_time = end_time - start_time  # 计算运行时间（单位为秒）
    print("脚本运行时间：", round(run_time, 2), '秒')
    print("--------------------------------------end-------------------------------")


def allpages():
    start_time = time.time()  # 记录开始时间
    # 调用列表接口，获取列表中三个字段的数据
    url = get_url('auditpageList4')
    headers = get_headers('auditpageList4')
    headers['Authorization'] = login()
    data = get_data('auditpageList4')
    ree = send_requests('auditpageList4', url, data, headers)
    a = json.loads(ree.text)
    list_all = a['data']['records']
    #流程名称列表
    list1 = []
    #流程发起人列表
    list2 = []
    #机构简称列表
    list3 = []
    for i in list_all:
        list1.append(i['auditConfigName'])
        list2.append(i['applyName'])
        if i['clientName'] is not None:
            list3.append(i['clientName'])

    # 处理机构简称列表数据
    original_list = list(set(list3))
    unique_list = deal_list(original_list)
    # 调用下拉框接口，获取下拉框选项数据
    url1 = get_url('auditgetDropDown4')
    headers1 = get_headers('auditgetDropDown4')
    headers1['Authorization'] = login()
    data1 = get_data('auditgetDropDown4')
    ree1 = send_requests( 'auditgetDropDown4', url1, data1, headers1)
    a1 = json.loads(ree1.text)

    # 流程名称下拉框列表
    list_auditConfigName = []
    # 流程发起人下拉框列表
    list_applyName = []
    # 机构简称下拉框列表
    list_examineContractName=[]

    for i in a1['data']['applyName']:
        list_applyName.append(i['label'])
    for i in a1['data']['auditConfigName']:
        list_auditConfigName.append(i['label'])
    for i in a1['data']['examineContractName']:
        list_examineContractName.append(i['label'])

    # 判断流程名称结果是否一致
    unique(list1, list_auditConfigName)

    # 判断流程发起人结果是否一致
    unique(list2, list_applyName)

    # 判断机构简称结果是否一致
    unique(unique_list, list_examineContractName)

    print("全部流程页面流程名称有" + str(len(set(list1))) + '个 ：' + str(set(list1)))
    print("全部流程页面流程发起人有" + str(len(set(list2))) + '个 ：' + str(set(list2)))
    print("全部流程页面机构简称有" + str(len(unique_list)) + '个 ：' + str(unique_list))
    end_time = time.time()  # 记录结束时间
    run_time = end_time - start_time  # 计算运行时间（单位为秒）
    print("脚本运行时间：", round(run_time, 2), '秒')
    print("--------------------------------------end-------------------------------")

def callback(future):
    print("Task done? ", future.done())
    print("Result: ", future.result())


with ThreadPoolExecutor(max_workers=5) as exe:
    exe.submit(pendingPage)
    exe.submit(processedpage)
    exe.submit(ccmypage)
    exe.submit(pageinitiated)
    exe.submit(allpages)






# # 创建线程对象
# thread1 = threading.Thread(target=pendingPage)
# thread2 = threading.Thread(target=processedpage)
# thread3 = threading.Thread(target=ccmypage)
# thread4 = threading.Thread(target=pageinitiated)
# thread5 = threading.Thread(target=allpages)
#
# #启动线程
# thread1.start()
# thread2.start()
# thread3.start()
# thread4.start()
# thread5.start()
# # 等待线程执行完成
# thread1.join()
# thread2.join()
# thread3.join()
# thread4.join()
# thread5.join()

# print("All threads have finished executing")